package com.stu.serive.impl;

import com.stu.context.BaseContext;
import com.stu.mapper.ClassInformationMapper;
import com.stu.mapper.CounsellorOperateMapper;
import com.stu.mapper.ViolationMapper;
import com.stu.pojo.ClassJobApplication;
import com.stu.pojo.ViolationApplication;
import com.stu.serive.CounsellorOperateService;
import com.stu.serive.aTService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
public class CounsellorOperateImpl implements CounsellorOperateService {

    @Autowired
    private CounsellorOperateMapper counsellorOperateMapper;
    @Autowired
    private ClassInformationMapper classInformationMapper;
    @Autowired
    private ViolationMapper violationMapper;

    /**
     * 审核奖学金审批
     * @param result
     */

    public void examineScholarship(Integer result, Integer id) {
        counsellorOperateMapper.examineScholarship(result, id);

    }

    /**
     * 审核班干部申请
     * @param result
     * @param id
     */
    @Transactional
    public void examineClassJob(Integer result, Integer id) {
        //修改班委申请表的辅导员审核状态
        counsellorOperateMapper.examineClassJob(result,id);
        //判断审核结果
        if(result == 2){//审核不通过
            return;
        }else{//审核通过
            //查询申请表获得classJobApplication
            ClassJobApplication classJobApplication = counsellorOperateMapper.selectJobApplication(Long.valueOf(id));
            log.info("classJobApplication：{}",classJobApplication);
            //根据class_id 操作班级表，修改对应的班委信息
            classInformationMapper.updateClassJob(classJobApplication);
        }
    }

    /**
     * 审核处分解除
     * @param result
     * @param id
     */
    @Transactional
    public void examineViolation(Integer result, Integer id) {
        //修改申请表中的审核状态
        counsellorOperateMapper.examineViolation(result, id, BaseContext.getCurrentId());
        //查询处分解除申请表获取外键
        ViolationApplication violationApplication = violationMapper.selectViolationApplicationById(id);
        //判断辅导员审核状态
        if(violationApplication.getAdminExamine() == 1 && result == 1){//对处分表上的信息进行删除
            violationMapper.deleteViolation(violationApplication.getViolationId());
        }
    }

    /**
     * 审核请假
     * @param result
     * @param id
     */
    public void examineExcuse(Integer result, Integer id) {
        //修改请假申请的审核状态
        counsellorOperateMapper.examineExcuse(result, id);
    }
}
